/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */





var info=new Vue({
  el:"#app",
  data:{
    scrollbar:{},
    data:[],
    isLoading:true,
    reqOut:false, //判断请求数据是否已完
    pageIndex :1,
    pageSize : PAGESIZE
  },
  created:function(){
      var dtd = $.Deferred();
      var _self = this;
      //商品列表
      var data = {
          pageSize: _self.pageSize,
          pageIndex:_self.pageIndex
      };
      data = Common.jsonEncode(data);
      _self.scrollbar = new scrollBar({
          isLoading: _self.isLoading,
          url: "user_getMyExchangeGoodsList",
          type:"get",
          data:data
      });
      
      _self.loadlist();
      
  },
  compiled:function(){
    var _self = this;
    $(document).scroll(function () {
      var docHeight = $(document).height(),
          winHeight = $(window).height();
      if ((docHeight > winHeight)&&($(document).scrollTop() >= docHeight - winHeight)) {
        if(!_self.reqOut){
          var str = '<img class="loading-img" src="images/loading.gif"></img>';
          myLoad.pullLoad('goodUl',str);
          
          info.loadlist(function(){
          });
        }
      }
    }); 

  },
  methods:{
    loadlist:function(callback){

      var _self = this;

      _self.scrollbar.load(function(pageIndex,data){
        for(var i = 0; i < data.length; i++){
          
          _self.data.push(data[i]);
        }
        _self.reqOut = false;

        //实际数据与请求的数据量比较
        if (data.length >= _self.pageSize) {
            myLoad.pullHide(); //加载后，把效果去掉
        } else {
            _self.reqOut = true;
            myLoad.noDate();
            _self.isLoading = false;
        }
        _self.pageIndex = pageIndex;
      },function(isLoading){
        _self.isLoading = isLoading;
        myLoad.noDate();
        _self.reqOut = true;
      });
      
    },
    loadPhoto:function(){
      // 比例
      myJS.imgScale('.j_4', '4', '3');
      myJS.ImgFull('.loadImg','images/liby.png');
    }

  },
  watch:{
      "data": function(){
          this.loadPhoto();
      }
  }

});



